<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>用户 明细</title>
    <link href="${root}/js/lib/ligerUI/skins/Aqua/css/ligerui-all.css" rel="stylesheet" type="text/css" />
    <link href="${root}/js/lib/ligerUI/skins/Gray/css/all.css" rel="stylesheet" type="text/css" />
    <script src="${root}/js/lib/jquery/jquery-1.5.2.min.js" type="text/javascript"></script>
    <script src="${root}/js/lib/ligerUI/js/ligerui.min.js" type="text/javascript"></script>  
    <link href="${root}/js/lib/css/common.css" rel="stylesheet" type="text/css" />  
    <script src="${root}/js/common/common.js" type="text/javascript"></script>    
    <script src="${root}/js/common/LG.js" type="text/javascript"></script>
    <script src="${root}/js/lib/jquery-validation/jquery.validate.min.js" type="text/javascript"></script> 
    <script src="${root}/js/lib/jquery-validation/jquery.metadata.js" type="text/javascript"></script>
    <script src="${root}/js/lib/jquery-validation/messages_cn.js" type="text/javascript"></script>
    <script src="${root}/js/lib/jquery.form.js" type="text/javascript"></script>
    <script src="${root}/js/lib/json2.js" type="text/javascript"></script>
    <script src="${root}/js/common/validator.js" type="text/javascript"></script>
    <script src="${root}/js/common/ligerui.expand.js" type="text/javascript"></script> 
    <script src="${root}/js/lib/ligerUI/js/plugins/ligerForm.js" type="text/javascript"></script>
    <script src="${root}/js/lib/ligerUI/js/plugins/ligerTree.js" type="text/javascript"></script>
    <script src="${root}/js/lib/ligerUI/js/plugins/ligerComboBox.js" type="text/javascript"></script>
</head>
<%
	String isView = request.getParameter("IsView");
	String currentID = request.getParameter("ID");
%>
<body style="padding-bottom:31px;">
    <form id="mainform" method="post"></form> 
    <script type="text/javascript"> 
  	//相对路径
    var rootPath = "${root}/";
        var config = {"Form":{ 
            fields : [
                      {name:"user_id",type:"hidden"},
                      {
                          display:"用户名",
                          name:"login_name",
                          newline:true,
                          labelWidth:100,
                          width:220,
                          space:30,
                          type:"text",
                          group:"基本信息",
                          groupicon:"${root}/js/lib/icons/32X32/communication.gif",
                          validate : {
                          	required:true,
                          	username:true,
                          	minlength:4,
                          	maxlength:25,
                          	remote:'${root}/app/isExistUser',
                          	messages:{
                        		required:'请输入用户名',
                        		remote:'用户名已经存在!'
                            		}
              				}
                      },
                      {display:"真实姓名",name:"nickname",newline:false,labelWidth:100,width:220,space:30,type:"text",validate:{required:true,minlength:1,maxlength:50,messages:{required:'请输入姓名',maxlength:'你的名字有这么长嘛？'}}},
                      {display:"密码",name:"password",newline:true,labelWidth:100,width:220,space:30,type:"password",validate:{maxlength:50,required:true,messages:{required:'请输入密码'}}},
                      {display:"确认密码",name:"password2",newline:false,labelWidth:100,width:220,space:30,type:"password",validate:{maxlength:50,required:true,equalTo:'#password',messages:{required:'请输入密码',equalTo:'两次密码输入不一致'}}},
                      {
                          display:"部门",
                          name:"department_id",
                          newline:true,
                          labelWidth:100,
                          width:220,
                          space:30,
                          type:"select",
                          comboboxName:"department_name",
                          options:{
                          	tree:{
                         		url :rootPath + 'app/userDeptJSON',
                         		checkbox:false,
                         		nodeWidth :220
                     		},
                     		valueFieldID:"department_id",
                     		valueField:"department_id"
                         	}
                   		},
                      {
                          display:"角色",
                          name:"role_id",
                          newline:false,
                          labelWidth:100,
                          width:220,
                          space:30,
                          type:"select",
                      	comboboxName:"UserRoleName",
                      	options:{
                        	valueFieldID:"role_id",
                        	url:rootPath + 'app/getRole',
                        	isMultiSelect:true,
                        	split:','}
                  		},
                      {display:"状态",name:"status",newline:true,labelWidth:100,width:220,space:30,type:"text",validate:{maxlength:50}},
                      {display:"密码修改状态",name:"password_status",newline:false,labelWidth:100,width:220,space:30,type:"text",validate:{maxlength:50}},
                      {display:"备注",name:"remark",newline:true,labelWidth:100,width:550,space:30,type:"textarea"}]
              }};;

        var forbidFields = [];

        LG.adujestConfig(config,forbidFields);

        var roleids = "";
        //当前ID
        var currentID = "<%=currentID%>";
        //是否新增状态
        var isAddNew = currentID == "" || currentID == "0";
        //是否查看状态
        var isView = <%=isView%>;
        //是否编辑状态
        var isEdit = !isAddNew && !isView;

        //覆盖本页面grid的loading效果
        LG.overrideGridLoading(); 

        
        //表单底部按钮 
        LG.setFormDefaultBtn(f_cancel,isView ? null : f_save);

        var deptTree = {
            url :rootPath + 'app/userDeptJSON',
            checkbox:false,
            nodeWidth :220
        };

        //创建表单结构
        var mainform = $("#mainform");  
        mainform.ligerForm({ 
         inputWidth: 280,
         fields : config.Form.fields,
		 toJSON:JSON2.stringify
        });

        $("#role_id").val(roleids);

        //var actionRoot = "../handler/ajax.ashx?type=AjaxMemberManage";
        if(isEdit){ 
            $("#login_name").attr("readonly", "readonly").removeAttr("validate");
            mainform.attr("action", rootPath + 'app/updateUser'); 
        }
        if (isAddNew) {
            mainform.attr("action", rootPath + 'app/addUser');
        }
        else { 
            LG.loadForm(mainform, { type: '/getUser', data: { ID: currentID} },f_loaded);
        }  

        
          
        if(!isView) 
        {
            //验证
            jQuery.metadata.setType("attr", "validate"); 
            LG.validate(mainform);
        } 

		function f_loaded()
        {
            if(!isView) return; 
            //查看状态，控制不能编辑
            $("input,select,textarea",mainform).attr("readonly", "readonly");
        }
        function f_save()
        {
            LG.submitForm(mainform, function (data) {
                var win = parent || window;
                if (data.IsError) {  
                    win.LG.showError('错误:' + data.Message);
                }
                else { 
                    win.LG.showSuccess('保存成功', function () { 
                        win.LG.closeAndReloadParent(null, "MemberManageUser");
                    });
                }
            });
        }
        function f_cancel()
        {
            var win = parent || window;
            win.LG.closeCurrentTab(null);
        }

		 
    </script>
</body>
</html>

